package com.six.firstpage.service.impl;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.six.core.entity.HeadNav;
import com.six.firstpage.service.HeadNavService;
import com.six.firstpage.mapper.HeadNavMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RestController;

import javax.crypto.interfaces.PBEKey;
import java.util.ArrayList;
import java.util.List;

/**
* @author ZZH
* @description 针对表【tb_head_nav】的数据库操作Service实现
* @createDate 2023-02-27 10:21:18
*/
@Service
public class HeadNavServiceImpl extends ServiceImpl<HeadNavMapper, HeadNav>
    implements HeadNavService{

    @Autowired
    private HeadNavMapper headNavMapper;


    //增加导航栏
     @Override
     public Integer addHeadNav(HeadNav headNav){
         return headNavMapper.insert(headNav);

     }

    //修改导航栏
    @Override
   public Integer updateHeadNav(HeadNav headNav){
        return headNavMapper.updateById(headNav);
    }

    //逻辑删除导航栏
    @Override
    public Integer delHeadNav(Integer headId){
        UpdateWrapper<HeadNav> wrapper = new UpdateWrapper<>();
        wrapper.eq("head_id",headId);
        wrapper.set("is_deleted",1);
        return headNavMapper.update(null,wrapper);
   }


    @Override
    public List<HeadNav> getAllHeadNav() {
        QueryWrapper<HeadNav> wrapper = new QueryWrapper<>();
        wrapper.eq("is_deleted",0);
        wrapper.eq("is_disable",0);

        List<HeadNav> headNavs = headNavMapper.selectList(wrapper);
        return headNavs;
    }

    //查询导航栏(条件查询)
    @Override
    public Page<HeadNav> getHeadNavByTitle(String title, Integer status,Integer current, Integer pageSize){

        Page<HeadNav> headNavPage = new Page<>(current,pageSize);
        QueryWrapper<HeadNav> wrapper= new QueryWrapper<>();
        wrapper.eq("is_deleted",0);
        if (!title.isEmpty()){
            wrapper.like("head_name",title);
        }
        if (status!=null){
            wrapper.eq("is_disable",status);
        }
        Page<HeadNav> page = headNavMapper.selectPage(headNavPage, wrapper);
        return page;

    }


}




